<?php 
class LoginController extends Controller{
	public function index(){
		if(IS_POST){
			$code = strtoupper($_POST['verify']);
			$admin = htmlspecialchars($_POST['userName']);
			$pwd = md5($_POST['psd']);
			if($_SESSION['code'] !=  $code)$this->error("验证码错误");
			$flat = M('hd_admin')->where("username='$admin' and passwd='$pwd'")->find();
			if(!empty($flat)){
				$_SESSION['admin'] = $admin;
				$_SESSION['aid'] = $flat['aid'];
				$this->success("登录成功",__APP__);
			}else{
				$f = M('hd_admin')->where("username='$admin'")->find();
				if(empty($f)){
					$this->error("用户名不存在！");
				}else{
					$this->error("密码错误！");
				}
			}

		}
		$this->display();
	}
	public function code(){
		$code = new Code;
		$code->show();
	}
}